package com.hsd.znsh.converter;

import com.hsd.znsh.entity.Host;
import com.hsd.znsh.entity.User;
import com.hsd.znsh.enums.RightEnum;
import com.hsd.znsh.pojo.output.HostVO;
import com.hsd.znsh.repository.UserRepository;
import com.hsd.znsh.utils.BeanUtil;

import java.util.ArrayList;
import java.util.List;

/*
 * @auther: wangjiacai
 *
 * @create: 2018-05-02 09:56:31
 */
public class HostConverter {

    public static HostVO converterToHostVO(Host host,UserRepository userRepository){
        HostVO hostVO=new HostVO();
        BeanUtil.copyPropertiesIgnoreNull(host,hostVO);
        if(host.getManagerId()!=null) hostVO.setManagerName(userRepository.findOne(host.getManagerId()).getUsername());
        return hostVO;
    }

    public static HostVO converterToHostVO(Host host,User user){
        HostVO hostVO=new HostVO();
        BeanUtil.copyPropertiesIgnoreNull(host,hostVO);
        if(host.getManagerId()== user.getCreateUserId()){
            hostVO.setRight(RightEnum.HAVE.getCode());
        }else{
            hostVO.setRight(RightEnum.MANAGEMENT.getCode());
        }
        return hostVO;
    }

    public static List<HostVO> converterToHostVOList(List<Host> hosts, User user){
        List<HostVO> list=new ArrayList<>();
        for(Host host:hosts){
            list.add(converterToHostVO(host,user));
        }
        return list;
    }

    public static List<HostVO> converterToHostVOList(List<Host> hosts,UserRepository userRepository){
        List<HostVO> list=new ArrayList<>();
        for(Host host:hosts){
            list.add(converterToHostVO(host,userRepository));
        }
        return list;
    }


}
